﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using Budget.DataAccess.Services;
using Budget.DataAccess;
using Budget.DataAccess.Repository;

namespace Budget.WCF
{
	// NOTE: If you change the class name "MthService" here, you must also update the reference to "MthService" in App.config.
	public class MthService : IMthService
	{
		private IMthDataService svc;

		#region IMthService Members

		public IList<Mth> GetAll()
		{
			if ( svc == null )
			{
				svc = new MthDataService( new BudgetRepository<Mth>( new BudgetDataContext() ) );
			}

			return svc.GetAll();
		}

		public Mth GetMthById( int mthId )
		{
			if ( svc == null )
			{
				BudgetDataContext context = new BudgetDataContext();
				BudgetRepository<Mth> repository = new BudgetRepository<Mth>( context );
				svc = new MthDataService( repository );
			}

			return svc.GetById( mthId );
		}

		public Mth GetByMonthAndYear( int month, int year )
		{
			if ( svc == null )
			{
				svc = new MthDataService( new BudgetRepository<Mth>( new BudgetDataContext() ) );
			}

			return svc.GetByMonthAndYear( month, year );
		}

		public void Save( Mth month )
		{
			if ( svc == null )
			{
				BudgetDataContext context = new BudgetDataContext();
				BudgetRepository<Mth> repository = new BudgetRepository<Mth>( context );
				svc = new MthDataService( repository );
			}

			svc.Save( month );
		}

		public bool DoesMonthYearExist( int month, int year )
		{
			if ( svc == null )
			{
				svc = new MthDataService( new BudgetRepository<Mth>( new BudgetDataContext() ) );
			}

			return svc.DoesMonthYearExist( month, year );
		}

		public Mth GetPreviousMonth( int mthId )
		{
			if ( svc == null )
			{
				svc = new MthDataService( new BudgetRepository<Mth>( new BudgetDataContext() ) );
			}

			return svc.GetPreviousMonth( mthId );
		}

		#endregion
	}
}
